<!DOCTYPE html>
<html lang="zh-CN">





<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/blog/img/favicon.png">
  <link rel="icon" type="image/png" href="/blog/img/favicon.png">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
    <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
  
  <meta name="theme-color" content="#35495e">
  <meta name="description" content="小菜头的博客，主要记录学习笔记，包含：html,css,javascript,jQuery,vue等">
  <meta name="author" content="A-cai">
  <meta name="keywords" content="html,css,javascript,jQuery,vue">
  <title>css 高效代码片段 - A-cai的blog</title>

  <link  rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.staticfile.org/github-markdown-css/4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/blog/lib/hint/hint.min.css" />

  
    <link  rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/10.0.0/styles/atom-one-dark.min.css" />
  

  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_yg9cfy8wd6.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_pjno9b9zyxs.css">


<link  rel="stylesheet" href="/blog/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script  src="/blog/js/utils.js" ></script>
<meta name="generator" content="Hexo 4.2.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/blog/">&nbsp;<strong>A-cai的学习笔记</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner intro-2" id="background" parallax=true
         style="background: url('/blog/img/default.png') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="container text-center white-text fade-in-up">
            <span class="h2" id="subtitle">
              
            </span>

            
              
  <div class="mt-3 post-meta">
    <i class="iconfont icon-date-fill" aria-hidden="true"></i>
    <time datetime="2020-06-26 13:59">
      2020年6月26日 下午
    </time>
  </div>


<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      5.6k 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      86
       分钟
    </span>
  

  
  
    
      <!-- 不蒜子统计文章PV -->
      <span id="busuanzi_container_page_pv" style="display: none">
        <i class="iconfont icon-eye" aria-hidden="true"></i>
        <span id="busuanzi_value_page_pv"></span> 次
      </span>
    
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid">
  <div class="row">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-md">
      <div class="container nopadding-md" id="board-ctn">
        <div class="py-5" id="board">
          <div class="post-content mx-auto" id="post">
            
              <p class="note note-info">
                
                  本文最后更新于：2020年3月26日 上午
                
              </p>
            
            <article class="markdown-body">
              <p>（给 JavaScript 加星标，提升我的前端技能.）</p>
<blockquote>
<p>作者：Eno_Yao</p>
<p><a href="https://github.com/Wscats/CV/issues/2" target="_blank" rel="noopener">https://github.com/Wscats/CV/issues/2</a></p>
</blockquote>
<p>这篇文章会记录我们平时常用到的 CSS 片段，使用这些 CSS 可以帮助我们解决许多实际项目中遇到的问题，强烈建议点赞收藏再看，方便日后查找。</p>
<h3 id="清除浮动"><a href="#清除浮动" class="headerlink" title="清除浮动"></a>清除浮动</h3><p>浮动给我们的代码带来的麻烦，想必不需要多说，我们会用很多方式来避免这种麻烦，其中我觉得最方便也是兼容性最好的一种是，在同级目录下再创建一个<code>&lt;div style=&quot;clear: both;&quot;&gt;&lt;/div&gt;</code>；不过这样会增加很多无用的代码。此时我们用<code>:after</code>这个伪元素来解决浮动的问题，如果当前层级有浮动元素，那么在其父级添加上 clearfix 类即可。</p>
<div class="hljs"><pre><code class="hljs css">//清除浮动
<span class="hljs-selector-class">.clearfix</span><span class="hljs-selector-pseudo">:after</span>&#123;
    <span class="hljs-attribute">content</span>: <span class="hljs-string">"\00A0"</span>;
    <span class="hljs-attribute">display</span>: block;
    <span class="hljs-attribute">visibility</span>: hidden;
    <span class="hljs-attribute">width</span>: <span class="hljs-number">0</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">0</span>;
    <span class="hljs-attribute">clear</span>: both;
    <span class="hljs-attribute">font-size</span>: <span class="hljs-number">0</span>;
    <span class="hljs-attribute">line-height</span>: <span class="hljs-number">0</span>;
    <span class="hljs-attribute">overflow</span>: hidden;
&#125;
<span class="hljs-selector-class">.clearfix</span>&#123;
    <span class="hljs-attribute">zoom</span>: <span class="hljs-number">1</span>;
&#125;</code></pre></div>

<h3 id="垂直水平居中"><a href="#垂直水平居中" class="headerlink" title="垂直水平居中"></a>垂直水平居中</h3><p>在 css 的世界里水平居中比垂直居中来的简单一些，经过了多年的演化，依然没有好的方式来让元素垂直居中。各种方式各有优缺点，但都不能达到兼容性好，破坏力小的目标，以下是几种常见的实现方式：</p>
<p>1、绝对定位方式且已知宽高</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">position</span>: <span class="hljs-selector-tag">absolute</span>;
<span class="hljs-selector-tag">top</span>: 50%;
<span class="hljs-selector-tag">left</span>: 50%;
<span class="hljs-selector-tag">margin-top</span>: <span class="hljs-selector-tag">-3em</span>;
<span class="hljs-selector-tag">margin-left</span>: <span class="hljs-selector-tag">-7em</span>;
<span class="hljs-selector-tag">width</span>: 14<span class="hljs-selector-tag">em</span>;
<span class="hljs-selector-tag">height</span>: 6<span class="hljs-selector-tag">em</span>;</code></pre></div>

<p>2、绝对定位＋未知宽高＋ translate</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">position</span>: <span class="hljs-selector-tag">absolute</span>;
<span class="hljs-selector-tag">left</span>: 50%;
<span class="hljs-selector-tag">top</span>: 50%;
<span class="hljs-selector-tag">transform</span>: <span class="hljs-selector-tag">translate</span>(<span class="hljs-selector-tag">-50</span>%,<span class="hljs-selector-tag">-50</span>%);
//需要补充浏览器前缀</code></pre></div>

<p>3、flex 轻松搞定水平垂直居中(未知宽高)</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">display</span>: <span class="hljs-selector-tag">flex</span>;
<span class="hljs-selector-tag">align-items</span>: <span class="hljs-selector-tag">center</span>;
<span class="hljs-selector-tag">justify-content</span>: <span class="hljs-selector-tag">center</span>;</code></pre></div>

<h3 id="文本末尾添加省略号"><a href="#文本末尾添加省略号" class="headerlink" title="文本末尾添加省略号"></a>文本末尾添加省略号</h3><p>当文本的内容超出容器的宽度的时候，我们希望在其默认添加省略号以达到提示用户内容省略显示的效果。</p>
<p>1、宽度固定，适合单行显示…</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">overflow</span>: <span class="hljs-selector-tag">hidden</span>;
<span class="hljs-selector-tag">text-overflow</span>: <span class="hljs-selector-tag">ellipsis</span>;
<span class="hljs-selector-tag">white-space</span>: <span class="hljs-selector-tag">nowrap</span>;</code></pre></div>

<p>2、宽度不固定，适合多行以及移动端显示</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">overflow</span>: <span class="hljs-selector-tag">hidden</span>;
<span class="hljs-selector-tag">text-overflow</span>: <span class="hljs-selector-tag">ellipsis</span>;
<span class="hljs-selector-tag">display</span>: <span class="hljs-selector-tag">-webkit-box</span>;
<span class="hljs-selector-tag">-webkit-line-clamp</span>: 3;
<span class="hljs-selector-tag">-webkit-box-orient</span>: <span class="hljs-selector-tag">vertical</span>;</code></pre></div>

<h3 id="制造文本的模糊效果"><a href="#制造文本的模糊效果" class="headerlink" title="制造文本的模糊效果"></a>制造文本的模糊效果</h3><p>当我们希望给文本制造一种模糊效果感觉的时候，可以这样做</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">color</span>: <span class="hljs-selector-tag">transparent</span>;
<span class="hljs-selector-tag">text-shadow</span>: 0 0 2<span class="hljs-selector-tag">px</span> <span class="hljs-selector-tag">rgba</span>(0, 0, 0, 0<span class="hljs-selector-class">.5</span>);</code></pre></div>

<h3 id="动画实现简洁-loading-效果"><a href="#动画实现简洁-loading-效果" class="headerlink" title="动画实现简洁 loading 效果"></a>动画实现简洁 loading 效果</h3><p>我们来实现一个非常简洁的 loading 效果</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.loading</span><span class="hljs-selector-pseudo">:after</span> &#123;
  <span class="hljs-attribute">display</span>: inline-block;
  <span class="hljs-attribute">overflow</span>: hidden;
  <span class="hljs-attribute">vertical-align</span>: bottom;
  <span class="hljs-attribute">content</span>: <span class="hljs-string">"\2026"</span>;
  <span class="hljs-attribute">-webkit-animation</span>: ellipsis <span class="hljs-number">2s</span> infinite;
&#125;

// 动画部分
<span class="hljs-keyword">@-webkit-keyframes</span> ellipsis &#123;
  <span class="hljs-selector-tag">from</span> &#123;
    <span class="hljs-attribute">width</span>: <span class="hljs-number">2px</span>;
  &#125;
  <span class="hljs-selector-tag">to</span> &#123;
    <span class="hljs-attribute">width</span>: <span class="hljs-number">15px</span>;
  &#125;
&#125;</code></pre></div>

<h3 id="自定义文本选中样式"><a href="#自定义文本选中样式" class="headerlink" title="自定义文本选中样式"></a>自定义文本选中样式</h3><p>默认情况下，我们在网页上选中文字的时候，会给选中的部分一个深蓝色背景颜色(可以自己拿起鼠标试试)，如果我们想自己定制被选中的部分的样式呢？</p>
<div class="hljs"><pre><code class="hljs css">// 注意只能修改这两个属性 字体颜色 选中背景颜色

<span class="hljs-selector-tag">element</span><span class="hljs-selector-pseudo">::selection</span> &#123;
  <span class="hljs-attribute">color</span>: green;
  <span class="hljs-attribute">background-color</span>: pink;
&#125;
<span class="hljs-selector-tag">element</span><span class="hljs-selector-pseudo">::-moz-selection</span> &#123;
  <span class="hljs-attribute">color</span>: green;
  <span class="hljs-attribute">background-color</span>: pink;
&#125;</code></pre></div>

<h3 id="顶角贴纸效果"><a href="#顶角贴纸效果" class="headerlink" title="顶角贴纸效果"></a>顶角贴纸效果</h3><p>有时候我们会有这样的需求，在一个列表展示页面，有一些列表项是新添加的、或者热度比较高的，就会要求在其上面添加一个贴纸效果的小条就像 hexo 默认博客的 fork me on github 那个效果一样。<br>接下来我们开始一步步完成最左边的这个效果</p>
<p>html 代码如下</p>
<div class="hljs"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"wrap"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"ribbon"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>Fork me on GitHub<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></code></pre></div>

<p>css 代码如下：</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-comment">/* 外层容器基本设置  */</span>
<span class="hljs-selector-class">.wrap</span> &#123;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">160px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">160px</span>;
  <span class="hljs-attribute">overflow</span>: hidden;
  <span class="hljs-attribute">position</span>: relative;
  <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#f3f3f3</span>;
&#125;

<span class="hljs-selector-class">.ribbon</span> &#123;
  <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#a00</span>;
  <span class="hljs-attribute">overflow</span>: hidden;
  <span class="hljs-attribute">white-space</span>: nowrap;
  <span class="hljs-attribute">position</span>: absolute;
  <span class="hljs-comment">/* shadom */</span>
  <span class="hljs-attribute">-webkit-box-shadow</span>: <span class="hljs-number">0</span> <span class="hljs-number">0</span> <span class="hljs-number">10px</span> <span class="hljs-number">#888</span>;
  <span class="hljs-attribute">-moz-box-shadow</span>: <span class="hljs-number">0</span> <span class="hljs-number">0</span> <span class="hljs-number">10px</span> <span class="hljs-number">#888</span>;
  <span class="hljs-attribute">box-shadow</span>: <span class="hljs-number">0</span> <span class="hljs-number">0</span> <span class="hljs-number">10px</span> <span class="hljs-number">#888</span>;
  <span class="hljs-comment">/* rotate */</span>
  <span class="hljs-attribute">-webkit-transform</span>: <span class="hljs-built_in">rotate</span>(-<span class="hljs-number">45deg</span>);
  <span class="hljs-attribute">-moz-transform</span>: <span class="hljs-built_in">rotate</span>(-<span class="hljs-number">45deg</span>);
  <span class="hljs-attribute">-ms-transform</span>: <span class="hljs-built_in">rotate</span>(-<span class="hljs-number">45deg</span>);
  <span class="hljs-attribute">-o-transform</span>: <span class="hljs-built_in">rotate</span>(-<span class="hljs-number">45deg</span>);
  <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">rotate</span>(-<span class="hljs-number">45deg</span>);
  <span class="hljs-comment">/* position */</span>
  <span class="hljs-attribute">left</span>: -<span class="hljs-number">50px</span>;
  <span class="hljs-attribute">top</span>: <span class="hljs-number">40px</span>;
&#125;

<span class="hljs-selector-class">.ribbon</span> <span class="hljs-selector-tag">a</span> &#123;
  <span class="hljs-attribute">border</span>: <span class="hljs-number">1px</span> solid <span class="hljs-number">#faa</span>;
  <span class="hljs-attribute">color</span>: <span class="hljs-number">#fff</span>;
  <span class="hljs-attribute">display</span>: block;
  <span class="hljs-attribute">font</span>: bold <span class="hljs-number">81.25%</span> <span class="hljs-string">"Helvetica Neue"</span>, Helvetica, Arial, sans-serif;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">1px</span> <span class="hljs-number">0</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">10px</span> <span class="hljs-number">50px</span>;
  <span class="hljs-attribute">text-align</span>: center;
  <span class="hljs-attribute">text-decoration</span>: none;
  <span class="hljs-comment">/* shadow */</span>
  <span class="hljs-attribute">text-shadow</span>: <span class="hljs-number">0</span> <span class="hljs-number">0</span> <span class="hljs-number">5px</span> <span class="hljs-number">#444</span>;
&#125;</code></pre></div>

<h3 id="input-占位符"><a href="#input-占位符" class="headerlink" title="input 占位符"></a>input 占位符</h3><p>当我们给部分 input 类型的设置 placeholder 属性的时候，有的时候需要修改其默认的样式。</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">input</span><span class="hljs-selector-pseudo">::-webkit-input-placeholder</span> &#123;
  <span class="hljs-attribute">color</span>: green;
  <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#f9f7f7</span>;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">14px</span>;
&#125;
<span class="hljs-selector-tag">input</span><span class="hljs-selector-pseudo">::-moz-input-placeholder</span> &#123;
  <span class="hljs-attribute">color</span>: green;
  <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#f9f7f7</span>;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">14px</span>;
&#125;
<span class="hljs-selector-tag">input</span><span class="hljs-selector-pseudo">::-ms-input-placeholder</span> &#123;
  <span class="hljs-attribute">color</span>: green;
  <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#f9f7f7</span>;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">14px</span>;
&#125;</code></pre></div>

<h3 id="移动端可点击元素去处默认边框"><a href="#移动端可点击元素去处默认边框" class="headerlink" title="移动端可点击元素去处默认边框"></a>移动端可点击元素去处默认边框</h3><p>在移动端浏览器上，当你点击一个链接或者通过 Javascript 定义的可点击元素的时候，会出现蓝色边框，说实话，这是很恶心的，怎么去掉呢?</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">-webkit-tap-highlight-color</span>: <span class="hljs-selector-tag">rgba</span>(255, 255, 255, 0);</code></pre></div>

<h3 id="首字下沉"><a href="#首字下沉" class="headerlink" title="首字下沉"></a>首字下沉</h3><p>要实现类似 word 中首字下沉的效果可以使用以下代码：</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">element</span><span class="hljs-selector-pseudo">:first-letter</span> &#123;
  <span class="hljs-attribute">float</span>: left;
  <span class="hljs-attribute">color</span>: green;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">30px</span>;
&#125;</code></pre></div>

<h3 id="小三角"><a href="#小三角" class="headerlink" title="小三角"></a>小三角</h3><p>在很多地方我们可以用得上小三角，接下来我们画一下四个方向的三角形。</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.triangle</span> &#123;
  <span class="hljs-comment">/* 基础样式 */</span>
  <span class="hljs-attribute">border</span>: solid <span class="hljs-number">10px</span> transparent;
&#125;
<span class="hljs-comment">/*下*/</span>
<span class="hljs-selector-class">.triangle</span><span class="hljs-selector-class">.bottom</span> &#123;
  <span class="hljs-attribute">border-top-color</span>: green;
&#125;
<span class="hljs-comment">/*上*/</span>
<span class="hljs-selector-class">.triangle</span><span class="hljs-selector-class">.top</span> &#123;
  <span class="hljs-attribute">border-bottom-color</span>: green;
&#125;
<span class="hljs-comment">/*左*/</span>
<span class="hljs-selector-class">.triangle</span><span class="hljs-selector-class">.top</span> &#123;
  <span class="hljs-attribute">border-right-color</span>: green;
&#125;
<span class="hljs-comment">/*右*/</span>
<span class="hljs-selector-class">.triangle</span><span class="hljs-selector-class">.top</span> &#123;
  <span class="hljs-attribute">border-left-color</span>: green;
&#125;</code></pre></div>

<p>可以看出画一个小三角非常简单，只要两行样式就可以搞定，对于方向只要想着画哪个方向则设置反方向的样式属性就可以</p>
<h3 id="鼠标手型"><a href="#鼠标手型" class="headerlink" title="鼠标手型"></a>鼠标手型</h3><p>一般情况下，我们希望在以下元素身上添加鼠标手型</p>
<ul>
<li><p>a</p>
</li>
<li><p>submit</p>
</li>
<li><p>input[type=”image”]</p>
</li>
<li><p>input[type=”button”]</p>
</li>
<li><p>button</p>
</li>
<li><p>label</p>
</li>
<li><p>select</p>
</li>
</ul>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">a</span><span class="hljs-selector-attr">[href]</span>,
<span class="hljs-selector-tag">input</span><span class="hljs-selector-attr">[type=<span class="hljs-string">"submit"</span>]</span>,
<span class="hljs-selector-tag">input</span><span class="hljs-selector-attr">[type=<span class="hljs-string">"image"</span>]</span>,
<span class="hljs-selector-tag">input</span><span class="hljs-selector-attr">[type=<span class="hljs-string">"button"</span>]</span>,
<span class="hljs-selector-tag">label</span><span class="hljs-selector-attr">[for]</span>,
<span class="hljs-selector-tag">select</span>,
<span class="hljs-selector-tag">button</span> &#123;
  <span class="hljs-attribute">cursor</span>: pointer;
&#125;</code></pre></div>

<h3 id="屏蔽-Webkit-移动浏览器中元素高亮效果"><a href="#屏蔽-Webkit-移动浏览器中元素高亮效果" class="headerlink" title="屏蔽 Webkit 移动浏览器中元素高亮效果"></a>屏蔽 Webkit 移动浏览器中元素高亮效果</h3><div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">-webkit-touch-callout</span>: <span class="hljs-selector-tag">none</span>;
<span class="hljs-selector-tag">-webkit-user-select</span>: <span class="hljs-selector-tag">none</span>;
<span class="hljs-selector-tag">-khtml-user-select</span>: <span class="hljs-selector-tag">none</span>;
<span class="hljs-selector-tag">-moz-user-select</span>: <span class="hljs-selector-tag">none</span>;
<span class="hljs-selector-tag">-ms-user-select</span>: <span class="hljs-selector-tag">none</span>;
<span class="hljs-selector-tag">user-select</span>: <span class="hljs-selector-tag">none</span>;</code></pre></div>

<h3 id="移除常用标签的浏览器默认的-margin-和-padding"><a href="#移除常用标签的浏览器默认的-margin-和-padding" class="headerlink" title="移除常用标签的浏览器默认的 margin 和 padding"></a>移除常用标签的浏览器默认的 margin 和 padding</h3><p>pre、code、legend、fieldset、blockquote…等标签不是很常用，所以就不一一列举，如果项目中使用到，可以自己单独写</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">body</span>,
<span class="hljs-selector-tag">p</span>,
<span class="hljs-selector-tag">h1</span>,
<span class="hljs-selector-tag">h2</span>,
<span class="hljs-selector-tag">h3</span>,
<span class="hljs-selector-tag">h4</span>,
<span class="hljs-selector-tag">h5</span>,
<span class="hljs-selector-tag">h6</span>,
<span class="hljs-selector-tag">dl</span>,
<span class="hljs-selector-tag">dd</span>,
<span class="hljs-selector-tag">ul</span>,
<span class="hljs-selector-tag">ol</span>,
<span class="hljs-selector-tag">th</span>,
<span class="hljs-selector-tag">td</span>,
<span class="hljs-selector-tag">button</span>,
<span class="hljs-selector-tag">figure</span>,
<span class="hljs-selector-tag">input</span>,
<span class="hljs-selector-tag">textarea</span>,
<span class="hljs-selector-tag">form</span> &#123;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">0</span>;
&#125;</code></pre></div>

<h3 id="统一-input、select、textarea-宽度"><a href="#统一-input、select、textarea-宽度" class="headerlink" title="统一 input、select、textarea 宽度"></a>统一 input、select、textarea 宽度</h3><p>不同浏览器的 input、select、textarea 的盒子模型宽度计算方式不同，统一为最常见的 content-box。</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">input</span>,
<span class="hljs-selector-tag">select</span>,
<span class="hljs-selector-tag">textarea</span> &#123;
  <span class="hljs-attribute">-webkit-box-sizing</span>: content-box;
  <span class="hljs-attribute">-moz-box-sizing</span>: content-box;
  <span class="hljs-attribute">box-sizing</span>: content-box;
&#125;

<span class="hljs-selector-tag">table</span> &#123;
  <span class="hljs-comment">/*table 相邻单元格的边框间的距离设置为 0*/</span>
  <span class="hljs-attribute">border-spacing</span>: <span class="hljs-number">0</span>;
  <span class="hljs-comment">/*默认情况下给 tr 设置 border 没有效果，如果 table 设置了边框为合并模式：border-collapse: collapse;就可以了*/</span>
  <span class="hljs-attribute">border-collapse</span>: collapse;
&#125;</code></pre></div>

<h3 id="移除浏览器部分元素的默认边框"><a href="#移除浏览器部分元素的默认边框" class="headerlink" title="移除浏览器部分元素的默认边框"></a>移除浏览器部分元素的默认边框</h3><p>acronym、fieldset… 等其他标签不是很常用，就不会一一列举；如果项目中用到，可以自己单独写。</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">img</span>,
<span class="hljs-selector-tag">input</span>,
<span class="hljs-selector-tag">button</span>,
<span class="hljs-selector-tag">textarea</span> &#123;
  <span class="hljs-attribute">border</span>: none;
  <span class="hljs-attribute">-webkit-appearance</span>: none;
&#125;

<span class="hljs-selector-tag">input</span> &#123;
  <span class="hljs-comment">/*由于 input 默认不继承父元素的居中样式，所以设置：text-align: inherit*/</span>
  <span class="hljs-attribute">text-align</span>: inherit;
&#125;

<span class="hljs-selector-tag">textarea</span> &#123;
  <span class="hljs-comment">/*textarea 默认不可以放缩*/</span>
  <span class="hljs-attribute">resize</span>: none;
&#125;</code></pre></div>

<h3 id="取消元素-outline-样式"><a href="#取消元素-outline-样式" class="headerlink" title="取消元素 outline 样式"></a>取消元素 outline 样式</h3><p>由于以下元素的部分属性没有继承父节点样式，所以声明这些元素的这些属性为父元素的属性。</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">a</span>,
<span class="hljs-selector-tag">h1</span>,
<span class="hljs-selector-tag">h2</span>,
<span class="hljs-selector-tag">h3</span>,
<span class="hljs-selector-tag">h4</span>,
<span class="hljs-selector-tag">h5</span>,
<span class="hljs-selector-tag">h6</span>,
<span class="hljs-selector-tag">input</span>,
<span class="hljs-selector-tag">select</span>,
<span class="hljs-selector-tag">button</span>,
<span class="hljs-selector-tag">option</span>,
<span class="hljs-selector-tag">textarea</span>,
<span class="hljs-selector-tag">optgroup</span> &#123;
  <span class="hljs-attribute">font-family</span>: inherit;
  <span class="hljs-attribute">font-size</span>: inherit;
  <span class="hljs-attribute">font-weight</span>: inherit;
  <span class="hljs-attribute">font-style</span>: inherit;
  <span class="hljs-attribute">line-height</span>: inherit;
  <span class="hljs-attribute">color</span>: inherit;
  <span class="hljs-attribute">outline</span>: none;
&#125;</code></pre></div>

<h3 id="取消超链接元素的默认文字装饰"><a href="#取消超链接元素的默认文字装饰" class="headerlink" title="取消超链接元素的默认文字装饰"></a>取消超链接元素的默认文字装饰</h3><div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">a</span> &#123;
  <span class="hljs-attribute">text-decoration</span>: none;
&#125;

<span class="hljs-selector-tag">ol</span>,
<span class="hljs-selector-tag">ul</span> &#123;
  <span class="hljs-comment">/*开发中 UI 设计的列表都是和原生的样式差太多，所以直接给取消 ol，ul 默认列表样式*/</span>
  <span class="hljs-attribute">list-style</span>: none;
&#125;

<span class="hljs-selector-tag">button</span>,
<span class="hljs-selector-tag">input</span><span class="hljs-selector-attr">[type=<span class="hljs-string">"submit"</span>]</span>,
<span class="hljs-selector-tag">input</span><span class="hljs-selector-attr">[type=<span class="hljs-string">"button"</span>]</span> &#123;
  <span class="hljs-comment">/*鼠标经过是"小手"形状表示可点击*/</span>
  <span class="hljs-attribute">cursor</span>: pointer;
&#125;

<span class="hljs-selector-tag">input</span><span class="hljs-selector-pseudo">::-moz-focus-inner</span> &#123;
  <span class="hljs-comment">/*取消火狐浏览器部分版本 input 聚焦时默认的"padding、border"*/</span>
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">border</span>: <span class="hljs-number">0</span>;
&#125;</code></pre></div>

<h3 id="取消部分浏览器数字输入控件的操作按钮"><a href="#取消部分浏览器数字输入控件的操作按钮" class="headerlink" title="取消部分浏览器数字输入控件的操作按钮"></a>取消部分浏览器数字输入控件的操作按钮</h3><div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">input</span><span class="hljs-selector-attr">[type=<span class="hljs-string">"number"</span>]</span> &#123;
  <span class="hljs-attribute">-moz-appearance</span>: textfield;
&#125;

<span class="hljs-selector-tag">input</span><span class="hljs-selector-attr">[type=<span class="hljs-string">"number"</span>]</span><span class="hljs-selector-pseudo">::-webkit-inner-spin-button</span>,
<span class="hljs-selector-tag">input</span><span class="hljs-selector-attr">[type=<span class="hljs-string">"number"</span>]</span><span class="hljs-selector-pseudo">::-webkit-outer-spin-button</span> &#123;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">-webkit-appearance</span>: none;
&#125;</code></pre></div>

<h3 id="输入控件-placeholder-色设置-999"><a href="#输入控件-placeholder-色设置-999" class="headerlink" title="输入控件 placeholder 色设置 #999"></a>输入控件 placeholder 色设置 #999</h3><div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">input</span><span class="hljs-selector-pseudo">::-webkit-input-placeholder</span>,
<span class="hljs-selector-tag">textarea</span><span class="hljs-selector-pseudo">::-webkit-input-placeholder</span> &#123;
  <span class="hljs-attribute">color</span>: <span class="hljs-number">#999</span>;
&#125;

<span class="hljs-selector-tag">input</span><span class="hljs-selector-pseudo">:-moz-placeholder</span>,
<span class="hljs-selector-tag">textarea</span><span class="hljs-selector-pseudo">:-moz-placeholder</span> &#123;
  <span class="hljs-attribute">color</span>: <span class="hljs-number">#999</span>;
&#125;

<span class="hljs-selector-tag">input</span><span class="hljs-selector-pseudo">::-moz-placeholder</span>,
<span class="hljs-selector-tag">textarea</span><span class="hljs-selector-pseudo">::-moz-placeholder</span> &#123;
  <span class="hljs-attribute">color</span>: <span class="hljs-number">#999</span>;
&#125;

<span class="hljs-selector-tag">input</span><span class="hljs-selector-pseudo">:-ms-input-placeholder</span>,
<span class="hljs-selector-tag">textarea</span><span class="hljs-selector-pseudo">:-ms-input-placeholder</span> &#123;
  <span class="hljs-attribute">color</span>: <span class="hljs-number">#999</span>;
&#125;

<span class="hljs-selector-tag">template</span> &#123;
  <span class="hljs-comment">/*由于部分浏览 template 会显示出来，所以要隐*/</span>
  <span class="hljs-attribute">display</span>: none;
&#125;</code></pre></div>

<h3 id="position-fixed-的缩写"><a href="#position-fixed-的缩写" class="headerlink" title="position:fixed 的缩写"></a>position:fixed 的缩写</h3><div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.pf</span> &#123;
  <span class="hljs-attribute">position</span>: fixed;
  <span class="hljs-comment">/*chrome 内核 浏览器 position: fixed 防止抖动*/</span>
  <span class="hljs-attribute">-webkit-transform</span>: <span class="hljs-built_in">translateZ</span>(<span class="hljs-number">0</span>);
&#125;</code></pre></div>

<h3 id="利用绝对定位宽高拉升原理，中心居中元素"><a href="#利用绝对定位宽高拉升原理，中心居中元素" class="headerlink" title="利用绝对定位宽高拉升原理，中心居中元素"></a>利用绝对定位宽高拉升原理，中心居中元素</h3><div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.middle</span> &#123;
  <span class="hljs-attribute">position</span>: absolute;
  <span class="hljs-attribute">top</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">right</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">bottom</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">left</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">margin</span>: auto;
&#125;</code></pre></div>

<h3 id="利用相对定位于-CSS3-使元素垂直居中"><a href="#利用相对定位于-CSS3-使元素垂直居中" class="headerlink" title="利用相对定位于 CSS3 使元素垂直居中"></a>利用相对定位于 CSS3 使元素垂直居中</h3><div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.v-middle</span> &#123;
  <span class="hljs-attribute">position</span>: relative;
  <span class="hljs-attribute">top</span>: <span class="hljs-number">50%</span>;
  <span class="hljs-attribute">-webkit-transform</span>: <span class="hljs-built_in">-webkit-translateY</span>(-<span class="hljs-number">50%</span>);
  <span class="hljs-attribute">-moz-transform</span>: <span class="hljs-built_in">-moz-translateY</span>(-<span class="hljs-number">50%</span>);
  <span class="hljs-attribute">-o-transform</span>: <span class="hljs-built_in">-o-translateY</span>(-<span class="hljs-number">50%</span>);
  <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">translateY</span>(-<span class="hljs-number">50%</span>);
&#125;</code></pre></div>

<h3 id="元素计算宽高的盒子模型以-border-为外界限-bb-gt-border-box"><a href="#元素计算宽高的盒子模型以-border-为外界限-bb-gt-border-box" class="headerlink" title="元素计算宽高的盒子模型以 border 为外界限 bb==&gt;border-box"></a>元素计算宽高的盒子模型以 border 为外界限 bb==&gt;border-box</h3><div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.bb</span> &#123;
  <span class="hljs-attribute">-webkit-box-sizing</span>: border-box;
  <span class="hljs-attribute">-moz-box-sizing</span>: border-box;
  <span class="hljs-attribute">box-sizing</span>: border-box;
&#125;</code></pre></div>

<h3 id="单行文本溢出显示省略号-to-gt-text-overflow"><a href="#单行文本溢出显示省略号-to-gt-text-overflow" class="headerlink" title="单行文本溢出显示省略号 to==&gt;text-overflow"></a>单行文本溢出显示省略号 to==&gt;text-overflow</h3><div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.to</span> &#123;
  <span class="hljs-attribute">overflow</span>: hidden;
  <span class="hljs-attribute">white-space</span>: nowrap;
  <span class="hljs-attribute">text-overflow</span>: ellipsis;
&#125;</code></pre></div>

<h3 id="初始化样式"><a href="#初始化样式" class="headerlink" title="初始化样式"></a>初始化样式</h3><p>不同的浏览器对各个标签默认的样式是不一样的，而且有时候我们也不想使用浏览器给出的默认样式，我们就可以用 reset.css 去掉其默认样式</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">body</span>,
<span class="hljs-selector-tag">h1</span>,
<span class="hljs-selector-tag">h2</span>,
<span class="hljs-selector-tag">h3</span>,
<span class="hljs-selector-tag">h4</span>,
<span class="hljs-selector-tag">h5</span>,
<span class="hljs-selector-tag">h6</span>,
<span class="hljs-selector-tag">hr</span>,
<span class="hljs-selector-tag">p</span>,
<span class="hljs-selector-tag">blockquote</span>,
<span class="hljs-selector-tag">dl</span>,
<span class="hljs-selector-tag">dt</span>,
<span class="hljs-selector-tag">dd</span>,
<span class="hljs-selector-tag">ul</span>,
<span class="hljs-selector-tag">ol</span>,
<span class="hljs-selector-tag">li</span>,
<span class="hljs-selector-tag">pre</span>,
<span class="hljs-selector-tag">form</span>,
<span class="hljs-selector-tag">fieldset</span>,
<span class="hljs-selector-tag">legend</span>,
<span class="hljs-selector-tag">button</span>,
<span class="hljs-selector-tag">input</span>,
<span class="hljs-selector-tag">textarea</span>,
<span class="hljs-selector-tag">th</span>,
<span class="hljs-selector-tag">td</span> &#123;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">0</span>;
&#125;
<span class="hljs-selector-tag">body</span>,
<span class="hljs-selector-tag">button</span>,
<span class="hljs-selector-tag">input</span>,
<span class="hljs-selector-tag">select</span>,
<span class="hljs-selector-tag">textarea</span> &#123;
  <span class="hljs-attribute">font</span>: <span class="hljs-number">12px</span>/<span class="hljs-number">1.5</span> tahoma, arial, \<span class="hljs-number">5</span>b8b\<span class="hljs-number">4</span>f53;
&#125;
<span class="hljs-selector-tag">h1</span>,
<span class="hljs-selector-tag">h2</span>,
<span class="hljs-selector-tag">h3</span>,
<span class="hljs-selector-tag">h4</span>,
<span class="hljs-selector-tag">h5</span>,
<span class="hljs-selector-tag">h6</span> &#123;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">100%</span>;
&#125;
<span class="hljs-selector-tag">address</span>,
<span class="hljs-selector-tag">cite</span>,
<span class="hljs-selector-tag">dfn</span>,
<span class="hljs-selector-tag">em</span>,
<span class="hljs-selector-tag">var</span> &#123;
  <span class="hljs-attribute">font-style</span>: normal;
&#125;
<span class="hljs-selector-tag">code</span>,
<span class="hljs-selector-tag">kbd</span>,
<span class="hljs-selector-tag">pre</span>,
<span class="hljs-selector-tag">samp</span> &#123;
  <span class="hljs-attribute">font-family</span>: couriernew, courier, monospace;
&#125;
<span class="hljs-selector-tag">small</span> &#123;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">12px</span>;
&#125;
<span class="hljs-selector-tag">ul</span>,
<span class="hljs-selector-tag">ol</span> &#123;
  <span class="hljs-attribute">list-style</span>: none;
&#125;
<span class="hljs-selector-tag">a</span> &#123;
  <span class="hljs-attribute">text-decoration</span>: none;
&#125;
<span class="hljs-selector-tag">a</span><span class="hljs-selector-pseudo">:hover</span> &#123;
  <span class="hljs-attribute">text-decoration</span>: underline;
&#125;
<span class="hljs-selector-tag">sup</span> &#123;
  <span class="hljs-attribute">vertical-align</span>: text-top;
&#125;
<span class="hljs-selector-tag">sub</span> &#123;
  <span class="hljs-attribute">vertical-align</span>: text-bottom;
&#125;
<span class="hljs-selector-tag">legend</span> &#123;
  <span class="hljs-attribute">color</span>: <span class="hljs-number">#000</span>;
&#125;
<span class="hljs-selector-tag">fieldset</span>,
<span class="hljs-selector-tag">img</span> &#123;
  <span class="hljs-attribute">border</span>: <span class="hljs-number">0</span>;
&#125;
<span class="hljs-selector-tag">button</span>,
<span class="hljs-selector-tag">input</span>,
<span class="hljs-selector-tag">select</span>,
<span class="hljs-selector-tag">textarea</span> &#123;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">100%</span>;
&#125;
<span class="hljs-selector-tag">table</span> &#123;
  <span class="hljs-attribute">border-collapse</span>: collapse;
  <span class="hljs-attribute">border-spacing</span>: <span class="hljs-number">0</span>;
&#125;</code></pre></div>

<h3 id="强制换行-自动换行-强制不换行"><a href="#强制换行-自动换行-强制不换行" class="headerlink" title="强制换行/自动换行/强制不换行"></a>强制换行/自动换行/强制不换行</h3><div class="hljs"><pre><code class="hljs css"><span class="hljs-comment">/* 强制不换行 */</span>
<span class="hljs-selector-tag">div</span> &#123;
  <span class="hljs-attribute">white-space</span>: nowrap;
&#125;

<span class="hljs-comment">/* 自动换行 */</span>
<span class="hljs-selector-tag">div</span> &#123;
  <span class="hljs-attribute">word-wrap</span>: break-word;
  <span class="hljs-attribute">word-break</span>: normal;
&#125;

<span class="hljs-comment">/* 强制英文单词断行 */</span>
<span class="hljs-selector-tag">div</span> &#123;
  <span class="hljs-attribute">word-break</span>: break-all;
&#125;</code></pre></div>

<h3 id="table-边界的样式"><a href="#table-边界的样式" class="headerlink" title="table 边界的样式"></a>table 边界的样式</h3><div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">table</span> &#123;
  <span class="hljs-attribute">border</span>: <span class="hljs-number">1px</span> solid <span class="hljs-number">#000</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">border-collapse</span>: collapse;
  <span class="hljs-attribute">table-layout</span>: fixed;
  <span class="hljs-attribute">margin-top</span>: <span class="hljs-number">10px</span>;
&#125;
<span class="hljs-selector-tag">table</span> <span class="hljs-selector-tag">td</span> &#123;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">30px</span>;
  <span class="hljs-attribute">border</span>: <span class="hljs-number">1px</span> solid <span class="hljs-number">#000</span>;
  <span class="hljs-attribute">background</span>: <span class="hljs-number">#fff</span>;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">15px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">3px</span> <span class="hljs-number">3px</span> <span class="hljs-number">3px</span> <span class="hljs-number">8px</span>;
  <span class="hljs-attribute">color</span>: <span class="hljs-number">#000</span>;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">160px</span>;
&#125;</code></pre></div>

<h3 id="绝对定位与-margin"><a href="#绝对定位与-margin" class="headerlink" title="绝对定位与 margin"></a>绝对定位与 margin</h3><p>当我们提前知道要居中元素的长度和宽度时，可以使用这种方式：</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.container</span> &#123;
  <span class="hljs-attribute">position</span>: relative;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">300px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">200px</span>;
  <span class="hljs-attribute">border</span>: <span class="hljs-number">1px</span> solid <span class="hljs-number">#333</span>;
&#125;
<span class="hljs-selector-class">.content</span> &#123;
  <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#ccc</span>;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">160px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">100px</span>;
  <span class="hljs-attribute">position</span>: absolute;
  <span class="hljs-attribute">top</span>: <span class="hljs-number">50%</span>;
  <span class="hljs-attribute">left</span>: <span class="hljs-number">50%</span>;
  <span class="hljs-attribute">margin-left</span>: -<span class="hljs-number">80px</span>; <span class="hljs-comment">/* 宽度的一半 */</span>
  <span class="hljs-attribute">margin-top</span>: -<span class="hljs-number">50px</span>; <span class="hljs-comment">/* 高度的一半 */</span>
&#125;</code></pre></div>

<h3 id="绝对定位与-transform"><a href="#绝对定位与-transform" class="headerlink" title="绝对定位与 transform"></a>绝对定位与 transform</h3><p>当要居中的元素不定宽和定高时，我们可以使用 transform 来让元素进行偏移。</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.container</span> &#123;
  <span class="hljs-attribute">position</span>: relative;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">300px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">200px</span>;
  <span class="hljs-attribute">border</span>: <span class="hljs-number">1px</span> solid <span class="hljs-number">#333</span>;
&#125;
<span class="hljs-selector-class">.content</span> &#123;
  <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#ccc</span>;
  <span class="hljs-attribute">position</span>: absolute;
  <span class="hljs-attribute">top</span>: <span class="hljs-number">50%</span>;
  <span class="hljs-attribute">left</span>: <span class="hljs-number">50%</span>;
  <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">translate3d</span>(-<span class="hljs-number">50%</span>, -<span class="hljs-number">50%</span>, <span class="hljs-number">0</span>);
  <span class="hljs-attribute">text-align</span>: center;
&#125;</code></pre></div>

<h3 id="line-height"><a href="#line-height" class="headerlink" title="line-height"></a>line-height</h3><p><code>line-height</code>其实是行高，我们可以用行高来调整布局！<br>不过这个方案有一个比较大的缺点是：文案必须是单行的，多行的话，设置的行高就会有问题。</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.container</span> &#123;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">300px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">200px</span>;
  <span class="hljs-attribute">border</span>: <span class="hljs-number">1px</span> solid <span class="hljs-number">#333</span>;
&#125;
<span class="hljs-selector-class">.content</span> &#123;
  <span class="hljs-attribute">line-height</span>: <span class="hljs-number">200px</span>;
&#125;</code></pre></div>

<h3 id="table-布局"><a href="#table-布局" class="headerlink" title="table 布局"></a>table 布局</h3><p>给容器元素设置<code>display:table</code>，当前元素设置<code>display:table-cell</code>：</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.container</span> &#123;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">300px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">200px</span>;
  <span class="hljs-attribute">border</span>: <span class="hljs-number">1px</span> solid <span class="hljs-number">#333</span>;
  <span class="hljs-attribute">display</span>: table;
&#125;
<span class="hljs-selector-class">.content</span> &#123;
  <span class="hljs-attribute">display</span>: table-cell;
  <span class="hljs-attribute">vertical-align</span>: middle;
  <span class="hljs-attribute">text-align</span>: center;
&#125;</code></pre></div>

<h3 id="flex-布局"><a href="#flex-布局" class="headerlink" title="flex 布局"></a>flex 布局</h3><p>我们可以给父级元素设置为<code>display:flex</code>，利用 flex 中的<code>align-items</code>和<code>justify-content</code>设置垂直方向和水平方向的居中。这种方式也不限制中间元素的宽度和高度。<br>同时，flex 布局也能替换<code>line-height</code>方案在某些 Android 机型中文字不居中的问题。</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.container</span> &#123;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">300px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">200px</span>;
  <span class="hljs-attribute">border</span>: <span class="hljs-number">1px</span> solid <span class="hljs-number">#333</span>;
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">align-items</span>: center;
  <span class="hljs-attribute">justify-content</span>: center;
&#125;
<span class="hljs-selector-class">.content</span> &#123;
  <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#ccc</span>;
  <span class="hljs-attribute">text-align</span>: center;
&#125;</code></pre></div>

<h3 id="图片上下左右居中"><a href="#图片上下左右居中" class="headerlink" title="图片上下左右居中"></a>图片上下左右居中</h3><p>一种常用的方式是把外层的 div 设置为 table-cell；然后让内部的元素上下左右居中。当然也还有一种方式，就是把 img 当做 div，参考 6 中的代码进行设置。<br>CSS 代码如下：</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.content</span> &#123;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">400px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">400px</span>;
  <span class="hljs-attribute">border</span>: <span class="hljs-number">1px</span> solid <span class="hljs-number">#ccc</span>;
  <span class="hljs-attribute">text-align</span>: center;
  <span class="hljs-attribute">display</span>: table-cell;
  <span class="hljs-attribute">vertical-align</span>: middle;
&#125;</code></pre></div>

<p>html 代码如下：</p>
<div class="hljs"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"content"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"./images.jpg"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"img"</span> /&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></code></pre></div>

<h3 id="标题两边的小横杠"><a href="#标题两边的小横杠" class="headerlink" title="标题两边的小横杠"></a>标题两边的小横杠</h3><p>我们经常会遇到这样的 UI 需求，就是标题两边有两个小横杠，之前是怎么实现的呢？比如用个<code>border-top</code>属性，然后再把中间的文字进行绝对定位，同时给这个文字一个背景颜色，把中间的这部分盖住。<br>现在我们可以使用伪元素来实现！</p>
<p>html 代码如下：</p>
<div class="hljs"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"title"</span>&gt;</span>标题<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></code></pre></div>

<p>css 代码如下：</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">title</span> &#123;
  <span class="hljs-attribute">color</span>: <span class="hljs-number">#e1767c</span>;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">0.3rem</span>;
  <span class="hljs-attribute">position</span>: relative;

  &amp;:before,
  &amp;<span class="hljs-selector-pseudo">:after</span> &#123;
    <span class="hljs-attribute">content</span>: <span class="hljs-string">""</span>;
    <span class="hljs-attribute">position</span>: absolute;
    <span class="hljs-attribute">display</span>: block;
    <span class="hljs-attribute">left</span>: <span class="hljs-number">50%</span>;
    <span class="hljs-attribute">top</span>: <span class="hljs-number">50%</span>;
    <span class="hljs-attribute">-webkit-transform</span>: <span class="hljs-built_in">translate3d</span>(-<span class="hljs-number">50%</span>, -<span class="hljs-number">50%</span>, <span class="hljs-number">0</span>);
    <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">translate3d</span>(-<span class="hljs-number">50%</span>, -<span class="hljs-number">50%</span>, <span class="hljs-number">0</span>);
    <span class="hljs-attribute">border-top</span>: <span class="hljs-number">0.02rem</span> solid <span class="hljs-number">#e1767c</span>;
    <span class="hljs-attribute">width</span>: <span class="hljs-number">0.4rem</span>;
  &#125;
  &amp;<span class="hljs-selector-pseudo">:before</span> &#123;
    <span class="hljs-attribute">margin-left</span>: -<span class="hljs-number">1.2rem</span>;
  &#125;
  &amp;<span class="hljs-selector-pseudo">:after</span> &#123;
    <span class="hljs-attribute">margin-left</span>: <span class="hljs-number">1.2rem</span>;
  &#125;
&#125;</code></pre></div>

<h3 id="用-border-属性绘制元素"><a href="#用-border-属性绘制元素" class="headerlink" title="用 border 属性绘制元素"></a>用 border 属性绘制元素</h3><p>border 除了作为简单的绘制边框以外，还可以绘制三角形，梯形，星形等任意的多边形，以下为绘制的两个三角形和梯形。</p>
<p>html 代码如下：</p>
<div class="hljs"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"triangle1"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"triangle2"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"trapezoid"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></code></pre></div>

<p>css 代码如下：</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.triangle1</span> &#123;
  <span class="hljs-comment">/*锐角三角形*/</span>
  <span class="hljs-attribute">width</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">border-top</span>: <span class="hljs-number">50px</span> solid transparent;
  <span class="hljs-attribute">border-bottom</span>: <span class="hljs-number">100px</span> solid <span class="hljs-number">#249ff1</span>;
  <span class="hljs-attribute">border-left</span>: <span class="hljs-number">30px</span> solid transparent;
  <span class="hljs-attribute">border-right</span>: <span class="hljs-number">100px</span> solid transparent;
&#125;
<span class="hljs-selector-class">.triangle2</span> &#123;
  <span class="hljs-comment">/*直角三角形*/</span>
  <span class="hljs-attribute">width</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">border-top</span>: <span class="hljs-number">80px</span> solid transparent;
  <span class="hljs-attribute">border-bottom</span>: <span class="hljs-number">80px</span> solid <span class="hljs-number">#ff5b01</span>;
  <span class="hljs-attribute">border-left</span>: <span class="hljs-number">50px</span> solid <span class="hljs-number">#ff5b01</span>;
  <span class="hljs-attribute">border-right</span>: <span class="hljs-number">50px</span> solid transparent;
&#125;
<span class="hljs-selector-class">.trapezoid</span> &#123;
  <span class="hljs-comment">/*梯形*/</span>
  <span class="hljs-attribute">width</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">border-top</span>: none;
  <span class="hljs-attribute">border-right</span>: <span class="hljs-number">80px</span> solid transparent;
  <span class="hljs-attribute">border-bottom</span>: <span class="hljs-number">60px</span> solid <span class="hljs-number">#13dbed</span>;
  <span class="hljs-attribute">border-left</span>: <span class="hljs-number">80px</span> solid <span class="hljs-number">#13dbed</span>;
&#125;</code></pre></div>

<h3 id="用-border-radius-绘制元素"><a href="#用-border-radius-绘制元素" class="headerlink" title="用 border-radius 绘制元素"></a>用 border-radius 绘制元素</h3><p><code>border-radius</code>主要用于绘制圆点、圆形、椭圆、圆角矩形等形状，以下为简单绘制的两个图形。</p>
<p>html 代码如下：</p>
<div class="hljs"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"circle"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"ellipse"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></code></pre></div>

<p>css 代码如下：</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.circle</span>,
<span class="hljs-selector-class">.ellipse</span> &#123;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">100px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">100px</span>;
  <span class="hljs-attribute">background</span>: <span class="hljs-number">#249ff1</span>;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">50%</span>;
&#125;
<span class="hljs-selector-class">.ellipse</span> &#123;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">150px</span>;
  <span class="hljs-attribute">background</span>: <span class="hljs-number">#ff9e01</span>;
&#125;</code></pre></div>

<p>但<code>border-radius</code>属性实际上可以设置最多 8 个值，通过改变 8 个值可以得到许多意想不到的图像。</p>
<h3 id="用-box-shadow-绘制元素"><a href="#用-box-shadow-绘制元素" class="headerlink" title="用 box-shadow 绘制元素"></a>用 box-shadow 绘制元素</h3><p>对于<code>box-shadow</code>，其完整的声明为：</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">box-shadow</span><span class="hljs-selector-pseudo">:h-shadow</span> <span class="hljs-selector-tag">v-shadow</span> <span class="hljs-selector-tag">blur</span> <span class="hljs-selector-tag">spread</span> <span class="hljs-selector-tag">color</span> <span class="hljs-selector-tag">inset</span></code></pre></div>

<p>各个值表示的意义分别为： 水平方向的偏移，垂直方向的偏移，模糊的距离（羽化值），阴影的大小（不设置或为 0 时阴影与主体的大小一致），阴影的颜色和是否使用内阴影。实际应用时可以接收 3-6 个值，对应分别如下：</p>
<ul>
<li>3 个值：h-shadow v-shadow color</li>
<li>4 个值：h-shadow v-shadow blur color</li>
<li>5 个值：h-shadow v-shadow blur spread color</li>
<li>6 个值：h-shadow v-shadow blur spread color inset</li>
</ul>
<p>同时，<code>border-shadow</code> 接受由多个以上各种值组成的以逗号分隔的值，通过这一特性，我们可以实现如多重边框的等效果。以下我们用该属性来实现一个单标签且不借助伪元素的「添加图标」和「代表目标」的的图标。</p>
<div class="hljs"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"plus"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"target"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></code></pre></div>

<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.plus</span> &#123;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">30px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">30px</span>;
  <span class="hljs-attribute">margin-left</span>: <span class="hljs-number">50px</span>; <span class="hljs-comment">/*由于box-shadow不占空间，常常需要添加margin来校正位置*/</span>
  <span class="hljs-attribute">background</span>: <span class="hljs-number">#000</span>;
  <span class="hljs-attribute">box-shadow</span>: <span class="hljs-number">0</span> -<span class="hljs-number">30px</span> <span class="hljs-number">0</span> red, <span class="hljs-number">0</span> <span class="hljs-number">30px</span> <span class="hljs-number">0</span> red, -<span class="hljs-number">30px</span> <span class="hljs-number">0</span> <span class="hljs-number">0</span> red, <span class="hljs-number">30px</span> <span class="hljs-number">0</span> <span class="hljs-number">0</span> red;
&#125;
<span class="hljs-selector-class">.target</span> &#123;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">30px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">30px</span>;
  <span class="hljs-attribute">background</span>: red;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">50%</span>;
  <span class="hljs-attribute">margin-left</span>: <span class="hljs-number">50px</span>;
  <span class="hljs-attribute">box-shadow</span>: <span class="hljs-number">0</span> <span class="hljs-number">0</span> <span class="hljs-number">0</span> <span class="hljs-number">10px</span> <span class="hljs-number">#fff</span>, <span class="hljs-number">0</span> <span class="hljs-number">0</span> <span class="hljs-number">0</span> <span class="hljs-number">20px</span> red, <span class="hljs-number">0</span> <span class="hljs-number">0</span> <span class="hljs-number">0</span> <span class="hljs-number">30px</span> <span class="hljs-number">#fff</span>, <span class="hljs-number">0</span> <span class="hljs-number">0</span> <span class="hljs-number">0</span> <span class="hljs-number">40px</span> red;
&#125;</code></pre></div>

<h3 id="使用-CSS-渐变来绘制图标"><a href="#使用-CSS-渐变来绘制图标" class="headerlink" title="使用 CSS 渐变来绘制图标"></a>使用 CSS 渐变来绘制图标</h3><p>CSS3 的渐变属性十分强大，理论上通过渐变可以绘制出任何的图形，渐变的特性和使用足足可以写一篇长文，以下为一个例子</p>
<p>html 代码如下：</p>
<div class="hljs"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"gradient"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></code></pre></div>

<p>css 代码如下：</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.gradient</span> &#123;
  <span class="hljs-attribute">position</span>: relative;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">300px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">300px</span>;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">50%</span>;
  <span class="hljs-attribute">background-color</span>: silver;
  <span class="hljs-attribute">background-image</span>: <span class="hljs-built_in">linear-gradient</span>(<span class="hljs-number">335deg</span>, #b00 <span class="hljs-number">23px</span>, transparent <span class="hljs-number">23px</span>),
    <span class="hljs-built_in">linear-gradient</span>(<span class="hljs-number">155deg</span>, #d00 <span class="hljs-number">23px</span>, transparent <span class="hljs-number">23px</span>), <span class="hljs-built_in">linear-gradient</span>(
      <span class="hljs-number">335deg</span>,
      #b00 <span class="hljs-number">23px</span>,
      transparent <span class="hljs-number">23px</span>
    ), <span class="hljs-built_in">linear-gradient</span>(<span class="hljs-number">155deg</span>, #d00 <span class="hljs-number">23px</span>, transparent <span class="hljs-number">23px</span>);
  <span class="hljs-attribute">background-size</span>: <span class="hljs-number">58px</span> <span class="hljs-number">58px</span>;
  <span class="hljs-attribute">background-position</span>: <span class="hljs-number">0px</span> <span class="hljs-number">2px</span>, <span class="hljs-number">4px</span> <span class="hljs-number">35px</span>, <span class="hljs-number">29px</span> <span class="hljs-number">31px</span>, <span class="hljs-number">34px</span> <span class="hljs-number">6px</span>;
&#125;</code></pre></div>

<ul>
<li>杯子</li>
</ul>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.cup</span> &#123;
  <span class="hljs-attribute">display</span>: inline-block;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">0.9em</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">0.4em</span>;
  <span class="hljs-attribute">border</span>: <span class="hljs-number">0.25em</span> solid;
  <span class="hljs-attribute">border-bottom</span>: <span class="hljs-number">1.1em</span> solid;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">0</span> <span class="hljs-number">0</span> <span class="hljs-number">0.25em</span> <span class="hljs-number">0.25em</span>;
&#125;
<span class="hljs-selector-tag">cup</span><span class="hljs-selector-pseudo">:before</span> &#123;
  <span class="hljs-attribute">position</span>: absolute;
  <span class="hljs-attribute">right</span>: -<span class="hljs-number">0.6em</span>;
  <span class="hljs-attribute">top</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">0.3em</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">0.8em</span>;
  <span class="hljs-attribute">border</span>: <span class="hljs-number">0.25em</span> solid;
  <span class="hljs-attribute">border-left</span>: none;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">0</span> <span class="hljs-number">0.25em</span> <span class="hljs-number">0.25em</span> <span class="hljs-number">0</span>;
  <span class="hljs-attribute">content</span>: <span class="hljs-string">""</span>;
&#125;</code></pre></div>

<ul>
<li>心形</li>
</ul>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.heart</span> &#123;
  <span class="hljs-attribute">display</span>: inline-block;
  <span class="hljs-attribute">margin-top</span>: <span class="hljs-number">1.5em</span>;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">50px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">50px</span>;
  <span class="hljs-attribute">background</span>: green;
&#125;
<span class="hljs-selector-class">.heart</span><span class="hljs-selector-pseudo">:before</span>,
<span class="hljs-selector-class">.heart</span><span class="hljs-selector-pseudo">:after</span> &#123;
  <span class="hljs-attribute">position</span>: absolute;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">1em</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">1.6em</span>;
  <span class="hljs-attribute">background</span>: <span class="hljs-number">#000</span>;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">50%</span> <span class="hljs-number">50%</span> <span class="hljs-number">0</span> <span class="hljs-number">0</span>;
  <span class="hljs-attribute">content</span>: <span class="hljs-string">""</span>;
  <span class="hljs-attribute">bottom</span>: <span class="hljs-number">0</span>;
&#125;
<span class="hljs-selector-class">.heart</span><span class="hljs-selector-pseudo">:before</span> &#123;
  <span class="hljs-attribute">-webkit-transform</span>: <span class="hljs-built_in">rotate</span>(<span class="hljs-number">45deg</span>);
  <span class="hljs-attribute">-webkit-transform-origin</span>: <span class="hljs-number">100%</span> <span class="hljs-number">100%</span>;
  <span class="hljs-attribute">right</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">background</span>: red;
  <span class="hljs-attribute">opacity</span>: <span class="hljs-number">0.5</span>;
  <span class="hljs-attribute">z-index</span>: <span class="hljs-number">5</span>;
&#125;
.<span class="hljs-selector-pseudo">:after</span> &#123;
  <span class="hljs-attribute">-webkit-transform</span>: <span class="hljs-built_in">rotate</span>(-<span class="hljs-number">45deg</span>);
  <span class="hljs-attribute">-webkit-transform-origin</span>: <span class="hljs-number">0</span> <span class="hljs-number">100%</span>;
  <span class="hljs-attribute">left</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">opacity</span>: <span class="hljs-number">0.8</span>;
&#125;</code></pre></div>

<ul>
<li>相机</li>
</ul>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.camera</span> &#123;
  <span class="hljs-attribute">display</span>: inline-block;
  <span class="hljs-attribute">border-style</span>: solid;
  <span class="hljs-attribute">border-width</span>: <span class="hljs-number">0.65em</span> <span class="hljs-number">0.9em</span>;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">0.1em</span>;
&#125;
<span class="hljs-selector-class">.camera</span><span class="hljs-selector-pseudo">:before</span> &#123;
  <span class="hljs-attribute">position</span>: absolute;
  <span class="hljs-attribute">top</span>: -<span class="hljs-number">0.3em</span>;
  <span class="hljs-attribute">left</span>: -<span class="hljs-number">0.3em</span>;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">0.4em</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">0.4em</span>;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">50%</span>;
  <span class="hljs-attribute">border</span>: <span class="hljs-number">0.1em</span> solid <span class="hljs-number">#fff</span>;
  <span class="hljs-attribute">box-shadow</span>: <span class="hljs-number">0</span> <span class="hljs-number">0</span> <span class="hljs-number">0</span> <span class="hljs-number">0.08em</span>, <span class="hljs-number">0</span> <span class="hljs-number">0</span> <span class="hljs-number">0</span> <span class="hljs-number">0.16em</span> <span class="hljs-number">#fff</span>;
  <span class="hljs-attribute">content</span>: <span class="hljs-string">""</span>;
&#125;
<span class="hljs-selector-class">.camera</span><span class="hljs-selector-pseudo">:after</span> &#123;
  <span class="hljs-attribute">position</span>: absolute;
  <span class="hljs-attribute">top</span>: -<span class="hljs-number">0.5em</span>;
  <span class="hljs-attribute">left</span>: <span class="hljs-number">0.5em</span>;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">0.2em</span>;
  <span class="hljs-attribute">border-top</span>: <span class="hljs-number">0.125em</span> solid <span class="hljs-number">#fff</span>;
  <span class="hljs-attribute">content</span>: <span class="hljs-string">""</span>;
&#125;</code></pre></div>

<ul>
<li>月亮</li>
</ul>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.moon</span> &#123;
  <span class="hljs-attribute">display</span>: inline-block;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">1.5em</span>;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">1.5em</span>;
  <span class="hljs-attribute">box-shadow</span>: inset -<span class="hljs-number">0.4em</span> <span class="hljs-number">0</span> <span class="hljs-number">0</span>;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">2em</span>;
  <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">rotate</span>(<span class="hljs-number">20deg</span>);
&#125;</code></pre></div>

<h3 id="浮动类"><a href="#浮动类" class="headerlink" title="浮动类"></a><strong>浮动类</strong></h3><p>常规浮动 list 浮动 image 浮动</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.float-left</span> &#123;
  <span class="hljs-attribute">float</span>: left;
&#125;
<span class="hljs-selector-class">.float-right</span> &#123;
  <span class="hljs-attribute">float</span>: right;
&#125;
<span class="hljs-selector-class">.float-li</span> <span class="hljs-selector-tag">li</span>,<span class="hljs-comment">/*定义到li父元素或祖先元素上*/</span> <span class="hljs-selector-tag">li</span><span class="hljs-selector-class">.float-li</span> &#123;
  <span class="hljs-attribute">float</span>: left;
&#125;
<span class="hljs-selector-class">.float-img</span> <span class="hljs-selector-tag">img</span>,<span class="hljs-comment">/*定义到img父元素或祖先元素上*/</span> <span class="hljs-selector-tag">img</span><span class="hljs-selector-class">.float-li</span> &#123;
  <span class="hljs-attribute">float</span>: left;
&#125;
<span class="hljs-selector-class">.float-span</span> <span class="hljs-selector-tag">span</span>,<span class="hljs-comment">/*定义到span父元素或祖先元素上*/</span> <span class="hljs-selector-tag">span</span><span class="hljs-selector-class">.float-span</span> &#123;
  <span class="hljs-attribute">float</span>: right;
&#125;</code></pre></div>

<h3 id="背景图片嵌入与定位"><a href="#背景图片嵌入与定位" class="headerlink" title="背景图片嵌入与定位"></a>背景图片嵌入与定位</h3><div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.bg-img</span> &#123;
  <span class="hljs-attribute">background-image</span>: <span class="hljs-built_in">url</span>(<span class="hljs-string">"../img/bg.png"</span>);
  <span class="hljs-attribute">background-position</span>: center top;
  <span class="hljs-attribute">background-repeat</span>: no-repeat;
&#125;
<span class="hljs-selector-class">.bg01-img</span> &#123;
  <span class="hljs-attribute">background-image</span>: <span class="hljs-built_in">url</span>(<span class="hljs-string">"../img/bg01.png"</span>);
  <span class="hljs-attribute">background-position</span>: center top;
  <span class="hljs-attribute">background-repeat</span>: no-repeat;
&#125;
<span class="hljs-selector-class">.bg02-img</span> &#123;
  <span class="hljs-attribute">background-image</span>: <span class="hljs-built_in">url</span>(<span class="hljs-string">"../img/bg02.png"</span>);
  <span class="hljs-attribute">background-position</span>: center top;
  <span class="hljs-attribute">background-repeat</span>: no-repeat;
&#125;
<span class="hljs-selector-class">.bg03-img</span> &#123;
  <span class="hljs-attribute">background-image</span>: <span class="hljs-built_in">url</span>(<span class="hljs-string">"../img/bg03.png"</span>);
  <span class="hljs-attribute">background-position</span>: center top;
  <span class="hljs-attribute">background-repeat</span>: no-repeat;
&#125;
<span class="hljs-selector-class">.bg04-img</span> &#123;
  <span class="hljs-attribute">background-image</span>: <span class="hljs-built_in">url</span>(<span class="hljs-string">"../img/bg04.png"</span>);
  <span class="hljs-attribute">background-position</span>: center top;
  <span class="hljs-attribute">background-repeat</span>: no-repeat;
&#125;</code></pre></div>

<h3 id="继承类"><a href="#继承类" class="headerlink" title="继承类"></a>继承类</h3><div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.inherit-width</span> &#123;
  <span class="hljs-attribute">width</span>: inherit;
&#125;
<span class="hljs-selector-class">.inherit-min-width</span> &#123;
  <span class="hljs-attribute">min-width</span>: inherit;
&#125;
<span class="hljs-selector-class">.inherit-height</span> &#123;
  <span class="hljs-attribute">height</span>: inherit;
&#125;
<span class="hljs-selector-class">.inherit-min-height</span> &#123;
  <span class="hljs-attribute">min-height</span>: inherit;
&#125;
<span class="hljs-selector-class">.inherit-color</span> &#123;
  <span class="hljs-attribute">color</span>: inherit;
&#125;</code></pre></div>

<h3 id="文本缩进"><a href="#文本缩进" class="headerlink" title="文本缩进"></a>文本缩进</h3><div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.text-indent</span> &#123;
  <span class="hljs-attribute">text-indent</span>: <span class="hljs-number">2rem</span>;
&#125;
<span class="hljs-comment">/*16px*/</span>
<span class="hljs-selector-class">.text-indent-xs</span> &#123;
  <span class="hljs-attribute">text-indent</span>: <span class="hljs-number">1.5rem</span>;
&#125;
<span class="hljs-comment">/*12px*/</span>
<span class="hljs-selector-class">.text-indent-sm</span> &#123;
  <span class="hljs-attribute">text-indent</span>: <span class="hljs-number">1.7rem</span>;
&#125;
<span class="hljs-comment">/*14px*/</span>
<span class="hljs-selector-class">.text-indent-md</span> &#123;
  <span class="hljs-attribute">text-indent</span>: <span class="hljs-number">2rem</span>;
&#125;
<span class="hljs-comment">/*18px*/</span>
<span class="hljs-selector-class">.text-indent-lg</span> &#123;
  <span class="hljs-attribute">text-indent</span>: <span class="hljs-number">2.4rem</span>;
&#125;
<span class="hljs-comment">/*20px*/</span></code></pre></div>

<h3 id="行高"><a href="#行高" class="headerlink" title="行高"></a>行高</h3><div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.line-height-xs</span> &#123;
  <span class="hljs-attribute">line-height</span>: <span class="hljs-number">1.3rem</span>;
&#125;
<span class="hljs-selector-class">.line-height-sm</span> &#123;
  <span class="hljs-attribute">line-height</span>: <span class="hljs-number">1.5rem</span>;
&#125;
<span class="hljs-selector-class">.line-height-md</span> &#123;
  <span class="hljs-attribute">line-height</span>: <span class="hljs-number">1.7rem</span>;
&#125;
<span class="hljs-selector-class">.line-height-lg</span> &#123;
  <span class="hljs-attribute">line-height</span>: <span class="hljs-number">2rem</span>;
&#125;

<span class="hljs-selector-class">.line-height-25x</span> &#123;
  <span class="hljs-attribute">line-height</span>: <span class="hljs-number">25px</span>;
&#125;
<span class="hljs-selector-class">.line-height-30x</span> &#123;
  <span class="hljs-attribute">line-height</span>: <span class="hljs-number">30px</span>;
&#125;</code></pre></div>

<h3 id="ul-缩进"><a href="#ul-缩进" class="headerlink" title="ul 缩进"></a>ul 缩进</h3><div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.ul-indent-xs</span> &#123;
  <span class="hljs-attribute">margin-left</span>: <span class="hljs-number">0.5rem</span>;
&#125;
<span class="hljs-selector-class">.ul-indent-sm</span> &#123;
  <span class="hljs-attribute">margin-left</span>: <span class="hljs-number">1rem</span>;
&#125;
<span class="hljs-selector-class">.ul-indent-md</span> &#123;
  <span class="hljs-attribute">margin-left</span>: <span class="hljs-number">1.5rem</span>;
&#125;
<span class="hljs-selector-class">.ul-indent-lg</span> &#123;
  <span class="hljs-attribute">margin-left</span>: <span class="hljs-number">2rem</span>;
&#125;
<span class="hljs-selector-class">.ol-list</span>,
<span class="hljs-selector-class">.ul-list</span> &#123;
  <span class="hljs-attribute">list-style</span>: disc;
&#125;</code></pre></div>

<h3 id="文本截断"><a href="#文本截断" class="headerlink" title="文本截断"></a>文本截断</h3><div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.truncate</span> &#123;
  <span class="hljs-attribute">max-width</span>: <span class="hljs-number">100%</span>;
  <span class="hljs-attribute">overflow</span>: hidden;
  <span class="hljs-attribute">text-overflow</span>: ellipsis;
  <span class="hljs-attribute">white-space</span>: nowrap;
&#125;
<span class="hljs-selector-class">.hide</span> &#123;
  <span class="hljs-attribute">display</span>: none;
&#125;</code></pre></div>

<h3 id="图片、视频规范"><a href="#图片、视频规范" class="headerlink" title="图片、视频规范"></a>图片、视频规范</h3><div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.img-max</span>,
<span class="hljs-selector-class">.video-max</span> &#123;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
  <span class="hljs-attribute">height</span>: auto;
&#125;
<span class="hljs-comment">/*display显示方式*/</span>
<span class="hljs-selector-class">.inline</span> &#123;
  <span class="hljs-attribute">display</span>: inline;
&#125;
<span class="hljs-selector-class">.inline-block</span> &#123;
  <span class="hljs-attribute">display</span>: inline-block;
&#125;
<span class="hljs-selector-class">.block</span> &#123;
  <span class="hljs-attribute">display</span>: block;
&#125;</code></pre></div>

<h3 id="边框样式"><a href="#边框样式" class="headerlink" title="边框样式"></a>边框样式</h3><div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.border-xs-black</span> &#123;
  <span class="hljs-attribute">border</span>: <span class="hljs-number">1px</span> solid <span class="hljs-number">#000</span>;
&#125;
<span class="hljs-selector-class">.border-sm-black</span> &#123;
  <span class="hljs-attribute">border</span>: <span class="hljs-number">2px</span> solid <span class="hljs-number">#000</span>;
&#125;
<span class="hljs-selector-class">.border-md-black</span> &#123;
  <span class="hljs-attribute">border</span>: <span class="hljs-number">3px</span> solid <span class="hljs-number">#000</span>;
&#125;
<span class="hljs-selector-class">.border-lg-black</span> &#123;
  <span class="hljs-attribute">border</span>: <span class="hljs-number">5px</span> solid <span class="hljs-number">#000</span>;
&#125;

<span class="hljs-selector-class">.border-xs-gray</span> &#123;
  <span class="hljs-attribute">border</span>: <span class="hljs-number">1px</span> solid <span class="hljs-number">#9c9c9c</span>;
&#125;
<span class="hljs-selector-class">.border-sm-gray</span> &#123;
  <span class="hljs-attribute">border</span>: <span class="hljs-number">2px</span> solid <span class="hljs-number">#9c9c9c</span>;
&#125;
<span class="hljs-selector-class">.border-md-gray</span> &#123;
  <span class="hljs-attribute">border</span>: <span class="hljs-number">3px</span> solid <span class="hljs-number">#9c9c9c</span>;
&#125;
<span class="hljs-selector-class">.border-lg-gray</span> &#123;
  <span class="hljs-attribute">border</span>: <span class="hljs-number">5px</span> solid <span class="hljs-number">#9c9c9c</span>;
&#125;</code></pre></div>

<h3 id="背景颜色"><a href="#背景颜色" class="headerlink" title="背景颜色"></a>背景颜色</h3><div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.bg-white</span> &#123;
  <span class="hljs-attribute">background</span>: <span class="hljs-number">#fff</span> <span class="hljs-meta">!important</span>;
&#125;
<span class="hljs-selector-class">.bg-black</span> &#123;
  <span class="hljs-attribute">background</span>: <span class="hljs-number">#1b1c1d</span> <span class="hljs-meta">!important</span>;
&#125;
<span class="hljs-selector-class">.bg-gray</span> &#123;
  <span class="hljs-attribute">background</span>: <span class="hljs-number">#767676</span> <span class="hljs-meta">!important</span>;
&#125;
<span class="hljs-selector-class">.bg-light-gray</span> &#123;
  <span class="hljs-attribute">background</span>: <span class="hljs-number">#f8f7f7</span> <span class="hljs-meta">!important</span>;
&#125;
<span class="hljs-selector-class">.bg-yellow</span> &#123;
  <span class="hljs-attribute">background</span>: <span class="hljs-number">#fbbd08</span> <span class="hljs-meta">!important</span>;
&#125;
<span class="hljs-selector-class">.bg-orange</span> &#123;
  <span class="hljs-attribute">background</span>: <span class="hljs-number">#f2711c</span> <span class="hljs-meta">!important</span>;
&#125;
<span class="hljs-selector-class">.bg-red</span> &#123;
  <span class="hljs-attribute">background</span>: <span class="hljs-number">#db2828</span> <span class="hljs-meta">!important</span>;
&#125;
<span class="hljs-selector-class">.bg-olive</span> &#123;
  <span class="hljs-attribute">background</span>: <span class="hljs-number">#b5cc18</span> <span class="hljs-meta">!important</span>;
&#125;
<span class="hljs-selector-class">.bg-green</span> &#123;
  <span class="hljs-attribute">background</span>: <span class="hljs-number">#21ba45</span> <span class="hljs-meta">!important</span>;
&#125;
<span class="hljs-selector-class">.bg-teal</span> &#123;
  <span class="hljs-attribute">background</span>: <span class="hljs-number">#00b5ad</span> <span class="hljs-meta">!important</span>;
&#125;
<span class="hljs-selector-class">.bg-darkGreen</span> &#123;
  <span class="hljs-attribute">background</span>: <span class="hljs-number">#19a97b</span> <span class="hljs-meta">!important</span>;
&#125;
<span class="hljs-selector-class">.bg-threeGreen</span> &#123;
  <span class="hljs-attribute">background</span>: <span class="hljs-number">#097c25</span> <span class="hljs-meta">!important</span>;
&#125;
<span class="hljs-selector-class">.bg-blue</span> &#123;
  <span class="hljs-attribute">background</span>: <span class="hljs-number">#2185d0</span> <span class="hljs-meta">!important</span>;
&#125;
<span class="hljs-selector-class">.bg-violet</span> &#123;
  <span class="hljs-attribute">background</span>: <span class="hljs-number">#6435c9</span> <span class="hljs-meta">!important</span>;
&#125;
<span class="hljs-selector-class">.bg-purple</span> &#123;
  <span class="hljs-attribute">background</span>: <span class="hljs-number">#a333c8</span> <span class="hljs-meta">!important</span>;
&#125;
<span class="hljs-selector-class">.bg-brown</span> &#123;
  <span class="hljs-attribute">background</span>: <span class="hljs-number">#a5673f</span> <span class="hljs-meta">!important</span>;
&#125;</code></pre></div>

<h3 id="分割线预设"><a href="#分割线预设" class="headerlink" title="分割线预设"></a>分割线预设</h3><div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">hr</span>,
<span class="hljs-selector-class">.hr-xs-Silver</span>,
<span class="hljs-selector-class">.hr-sm-black</span>,
<span class="hljs-selector-class">.hr-sm-Silver</span>,
<span class="hljs-selector-class">.hr-xs-gray</span>,
<span class="hljs-selector-class">.hr-sm-gray</span> &#123;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">20px</span> <span class="hljs-number">0</span>;
&#125;
<span class="hljs-selector-tag">hr</span> &#123;
  <span class="hljs-attribute">border</span>: none;
  <span class="hljs-attribute">border-top</span>: <span class="hljs-number">1px</span> solid <span class="hljs-number">#000</span>;
&#125;
<span class="hljs-selector-class">.hr-xs-Silver</span> &#123;
  <span class="hljs-attribute">border</span>: none;
  <span class="hljs-attribute">border-top</span>: <span class="hljs-number">1px</span> solid <span class="hljs-number">#c0c0c0</span>;
&#125;
<span class="hljs-selector-class">.hr-sm-black</span> &#123;
  <span class="hljs-attribute">border</span>: none;
  <span class="hljs-attribute">border-top</span>: <span class="hljs-number">2px</span> solid <span class="hljs-number">#000</span>;
&#125;
<span class="hljs-selector-class">.hr-sm-Silver</span> &#123;
  <span class="hljs-attribute">border</span>: none;
  <span class="hljs-attribute">border-top</span>: <span class="hljs-number">2px</span> solid <span class="hljs-number">#c0c0c0</span>;
&#125;
<span class="hljs-selector-class">.hr-xs-gray</span> &#123;
  <span class="hljs-attribute">border</span>: none;
  <span class="hljs-attribute">border-top</span>: <span class="hljs-number">1px</span> solid <span class="hljs-number">#767676</span>;
&#125;
<span class="hljs-selector-class">.hr-sm-gray</span> &#123;
  <span class="hljs-attribute">border</span>: none;
  <span class="hljs-attribute">border-top</span>: <span class="hljs-number">2px</span> solid <span class="hljs-number">#767676</span>;
&#125;</code></pre></div>

<h3 id="鼠标-a-标签-hover-效果"><a href="#鼠标-a-标签-hover-效果" class="headerlink" title="鼠标 a 标签 hover 效果"></a>鼠标 a 标签 hover 效果</h3><div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.hover-red</span> <span class="hljs-selector-tag">a</span><span class="hljs-selector-pseudo">:hover</span>,<span class="hljs-comment">/*为a标签祖先元素添加类名 默认无智能提醒*/</span> <span class="hljs-selector-tag">a</span><span class="hljs-selector-class">.hover-red</span><span class="hljs-selector-pseudo">:hover</span> &#123;
  <span class="hljs-attribute">color</span>: red;
&#125; <span class="hljs-comment">/*单独为a标签添加类名*/</span>
<span class="hljs-selector-class">.hover-yellow</span> <span class="hljs-selector-tag">a</span><span class="hljs-selector-pseudo">:hover</span>,<span class="hljs-comment">/*为a标签祖先元素添加类名 默认无智能提醒*/</span> <span class="hljs-selector-tag">a</span><span class="hljs-selector-class">.hover-yellow</span><span class="hljs-selector-pseudo">:hover</span> &#123;
  <span class="hljs-attribute">color</span>: <span class="hljs-number">#ffd700</span>;
&#125; <span class="hljs-comment">/*单独为a标签添加类名*/</span>
<span class="hljs-selector-class">.hover-green</span> <span class="hljs-selector-tag">a</span><span class="hljs-selector-pseudo">:hover</span>,<span class="hljs-comment">/*为a标签祖先元素添加类名 默认无智能提醒*/</span> <span class="hljs-selector-tag">a</span><span class="hljs-selector-class">.hover-green</span><span class="hljs-selector-pseudo">:hover</span> &#123;
  <span class="hljs-attribute">color</span>: <span class="hljs-number">#70aa39</span>;
&#125; <span class="hljs-comment">/*单独为a标签添加类名*/</span>
<span class="hljs-selector-class">.hover-blue</span> <span class="hljs-selector-tag">a</span><span class="hljs-selector-pseudo">:hover</span>,<span class="hljs-comment">/*为a标签祖先元素添加类名 默认无智能提醒*/</span> <span class="hljs-selector-tag">a</span><span class="hljs-selector-class">.hover-blue</span><span class="hljs-selector-pseudo">:hover</span> &#123;
  <span class="hljs-attribute">color</span>: blue;
&#125; <span class="hljs-comment">/*单独为a标签添加类名*/</span>
<span class="hljs-selector-class">.hover-gray</span> <span class="hljs-selector-tag">a</span><span class="hljs-selector-pseudo">:hover</span>,<span class="hljs-comment">/*为a标签祖先元素添加类名 默认无智能提醒*/</span> <span class="hljs-selector-tag">a</span><span class="hljs-selector-class">.hover-gray</span><span class="hljs-selector-pseudo">:hover</span> &#123;
  <span class="hljs-attribute">color</span>: <span class="hljs-number">#9c9c9c</span>;
&#125; <span class="hljs-comment">/*单独为a标签添加类名*/</span>
<span class="hljs-selector-class">.underline</span> <span class="hljs-selector-tag">a</span><span class="hljs-selector-pseudo">:hover</span>,
<span class="hljs-selector-tag">a</span><span class="hljs-selector-class">.underline</span><span class="hljs-selector-pseudo">:hover</span> &#123;
  <span class="hljs-attribute">text-decoration</span>: underline;
&#125;</code></pre></div>

<h3 id="阴影效果"><a href="#阴影效果" class="headerlink" title="阴影效果"></a>阴影效果</h3><div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.shadow-text-xs</span> &#123;
  <span class="hljs-attribute">text-shadow</span>: <span class="hljs-number">4px</span> <span class="hljs-number">3px</span> <span class="hljs-number">0</span> <span class="hljs-number">#1d9d74</span>, <span class="hljs-number">9px</span> <span class="hljs-number">8px</span> <span class="hljs-number">0</span> <span class="hljs-built_in">rgba</span>(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0.15</span>);
&#125; <span class="hljs-comment">/*智能兼容ie10以上 暂不考虑*/</span>

<span class="hljs-selector-class">.shadow-xs</span> &#123;
  <span class="hljs-attribute">-ms-filter</span>: <span class="hljs-string">"progid:DXImageTransform.Microsoft.Shadow(Strength=1, Direction=100, Color='#cccccc')"</span>; <span class="hljs-comment">/* For IE 8 */</span>
  <span class="hljs-attribute">filter</span>: progid:DXImageTransform.Microsoft.<span class="hljs-built_in">Shadow</span>(Strength=<span class="hljs-number">1</span>, Direction=<span class="hljs-number">100</span>, Color=<span class="hljs-string">'#cccccc'</span>); <span class="hljs-comment">/* For IE 5.5 - 7 */</span>
  <span class="hljs-attribute">-moz-box-shadow</span>: <span class="hljs-number">1px</span> <span class="hljs-number">1px</span> <span class="hljs-number">2px</span> <span class="hljs-number">#cccccc</span>; <span class="hljs-comment">/* for firefox */</span>
  <span class="hljs-attribute">-webkit-box-shadow</span>: <span class="hljs-number">1px</span> <span class="hljs-number">1px</span> <span class="hljs-number">2px</span> <span class="hljs-number">#cccccc</span>; <span class="hljs-comment">/* for safari or chrome */</span>
  <span class="hljs-attribute">box-shadow</span>: <span class="hljs-number">1px</span> <span class="hljs-number">1px</span> <span class="hljs-number">2px</span> <span class="hljs-number">#cccccc</span>; <span class="hljs-comment">/* for opera or ie9 */</span>
&#125;
<span class="hljs-selector-class">.shadow-sm</span> &#123;
  <span class="hljs-attribute">-ms-filter</span>: <span class="hljs-string">"progid:DXImageTransform.Microsoft.Shadow(Strength=2, Direction=120, Color='#cccccc')"</span>; <span class="hljs-comment">/* For IE 8 */</span>
  <span class="hljs-attribute">filter</span>: progid:DXImageTransform.Microsoft.<span class="hljs-built_in">Shadow</span>(Strength=<span class="hljs-number">2</span>, Direction=<span class="hljs-number">120</span>, Color=<span class="hljs-string">'#cccccc'</span>); <span class="hljs-comment">/* For IE 5.5 - 7 */</span>
  <span class="hljs-attribute">-moz-box-shadow</span>: <span class="hljs-number">2px</span> <span class="hljs-number">2px</span> <span class="hljs-number">3px</span> <span class="hljs-number">#cccccc</span>; <span class="hljs-comment">/* for firefox */</span>
  <span class="hljs-attribute">-webkit-box-shadow</span>: <span class="hljs-number">2px</span> <span class="hljs-number">2px</span> <span class="hljs-number">3px</span> <span class="hljs-number">#cccccc</span>; <span class="hljs-comment">/* for safari or chrome */</span>
  <span class="hljs-attribute">box-shadow</span>: <span class="hljs-number">2px</span> <span class="hljs-number">2px</span> <span class="hljs-number">3px</span> <span class="hljs-number">#cccccc</span>; <span class="hljs-comment">/* for opera or ie9 */</span>
&#125;
<span class="hljs-selector-class">.shadow-md</span> &#123;
  <span class="hljs-attribute">-ms-filter</span>: <span class="hljs-string">"progid:DXImageTransform.Microsoft.Shadow(Strength=3, Direction=135, Color='#cccccc')"</span>; <span class="hljs-comment">/* For IE 8 */</span>
  <span class="hljs-attribute">filter</span>: progid:DXImageTransform.Microsoft.<span class="hljs-built_in">Shadow</span>(Strength=<span class="hljs-number">3</span>, Direction=<span class="hljs-number">135</span>, Color=<span class="hljs-string">'#cccccc'</span>); <span class="hljs-comment">/* For IE 5.5 - 7 */</span>
  <span class="hljs-attribute">-moz-box-shadow</span>: <span class="hljs-number">3px</span> <span class="hljs-number">3px</span> <span class="hljs-number">5px</span> <span class="hljs-number">#cccccc</span>; <span class="hljs-comment">/* for firefox */</span>
  <span class="hljs-attribute">-webkit-box-shadow</span>: <span class="hljs-number">3px</span> <span class="hljs-number">3px</span> <span class="hljs-number">5px</span> <span class="hljs-number">#cccccc</span>; <span class="hljs-comment">/* for safari or chrome */</span>
  <span class="hljs-attribute">box-shadow</span>: <span class="hljs-number">3px</span> <span class="hljs-number">3px</span> <span class="hljs-number">5px</span> <span class="hljs-number">#cccccc</span>; <span class="hljs-comment">/* for opera or ie9 */</span>
&#125;
<span class="hljs-selector-class">.shadow-lg</span> &#123;
  <span class="hljs-attribute">-ms-filter</span>: <span class="hljs-string">"progid:DXImageTransform.Microsoft.Shadow(Strength=5, Direction=150, Color='#cccccc')"</span>; <span class="hljs-comment">/* For IE 8 */</span>
  <span class="hljs-attribute">filter</span>: progid:DXImageTransform.Microsoft.<span class="hljs-built_in">Shadow</span>(Strength=<span class="hljs-number">5</span>, Direction=<span class="hljs-number">150</span>, Color=<span class="hljs-string">'#cccccc'</span>); <span class="hljs-comment">/* For IE 5.5 - 7 */</span>
  <span class="hljs-attribute">-moz-box-shadow</span>: <span class="hljs-number">5px</span> <span class="hljs-number">5px</span> <span class="hljs-number">8px</span> <span class="hljs-number">#cccccc</span>; <span class="hljs-comment">/* for firefox */</span>
  <span class="hljs-attribute">-webkit-box-shadow</span>: <span class="hljs-number">5px</span> <span class="hljs-number">5px</span> <span class="hljs-number">8px</span> <span class="hljs-number">#cccccc</span>; <span class="hljs-comment">/* for safari or chrome */</span>
  <span class="hljs-attribute">box-shadow</span>: <span class="hljs-number">5px</span> <span class="hljs-number">5px</span> <span class="hljs-number">8px</span> <span class="hljs-number">#cccccc</span>; <span class="hljs-comment">/* for opera or ie9 */</span>
&#125;</code></pre></div>

<h3 id="圆角"><a href="#圆角" class="headerlink" title="圆角"></a>圆角</h3><div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.border-radius-xs</span> &#123;
  <span class="hljs-attribute">-webkit-border-radius</span>: <span class="hljs-number">3px</span>;
  <span class="hljs-attribute">-moz-border-radius</span>: <span class="hljs-number">3px</span>;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">3px</span>;
&#125;
<span class="hljs-selector-class">.border-radius-sm</span> &#123;
  <span class="hljs-attribute">-webkit-border-radius</span>: <span class="hljs-number">5px</span>;
  <span class="hljs-attribute">-moz-border-radius</span>: <span class="hljs-number">5px</span>;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">5px</span>;
&#125;
<span class="hljs-selector-class">.border-radius-md</span> &#123;
  <span class="hljs-attribute">-webkit-border-radius</span>: <span class="hljs-number">7px</span>;
  <span class="hljs-attribute">-moz-border-radius</span>: <span class="hljs-number">5px</span>;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">5px</span>;
&#125;
<span class="hljs-selector-class">.border-radius-lg</span> &#123;
  <span class="hljs-attribute">-webkit-border-radius</span>: <span class="hljs-number">9px</span>;
  <span class="hljs-attribute">-moz-border-radius</span>: <span class="hljs-number">9px</span>;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">9px</span>;
&#125;</code></pre></div>

<p>如果文章和笔记能带您一丝帮助或者启发，请不要吝啬你的赞和收藏，你的肯定是我前进的最大动力。<br><img src="https://mmbiz.qpic.cn/mmbiz_png/btsCOHx9LAPWWsjRocrDTkNwLZloQWZ36IdgR3UF3aPwKE5juHUXicFU10wN2Pw9ObAjlIXZ5J0iaufdicuINIjww/640?wx_fmt=png" srcset="/blog/img/loading.gif" alt=""><br>好文和朋友一起看~</p>

            </article>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                
              </div>
              
                <p class="note note-warning">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" target="_blank" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！</p>
              
              
                <div class="post-prevnext row">
                  <div class="post-prev col-6">
                    
                    
                      <a href="/blog/2020/06/26/%E6%BB%9A%E5%8A%A8%E6%9D%A1MDN%E5%8F%82%E8%80%83%E6%96%87%E6%A1%A3/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">滚动条MDN参考文档</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </div>
                  <div class="post-next col-6">
                    
                    
                      <a href="/blog/2020/06/26/css%20Grid%E5%B8%83%E5%B1%80/">
                        <span class="hidden-mobile">css Grid布局</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </div>
                </div>
              
            </div>

            
              <!-- Comments -->
              <div class="comments" id="comments">
                
                

              </div>
            
          </div>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div id="tocbot"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    
  </main>

  
    <a id="scroll-top-button" href="#" role="button">
      <i class="iconfont icon-arrowup" aria-hidden="true"></i>
    </a>
  

  
    <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
  

  

  

  <footer class="mt-5">
  <div class="text-center py-3">
    <div>
      <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a>
      <i class="iconfont icon-love"></i>
      <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener">
        <span>Fluid</span></a>
    </div>
    

    

    
  </div>
</footer>

<!-- SCRIPTS -->
<script  src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js" ></script>
<script  src="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/js/bootstrap.min.js" ></script>
<script  src="/blog/js/debouncer.js" ></script>
<script  src="/blog/js/main.js" ></script>

<!-- Plugins -->


  
    <script  src="/blog/js/lazyload.js" ></script>
  



  <script defer src="https://cdn.staticfile.org/clipboard.js/2.0.6/clipboard.min.js" ></script>
  <script  src="/blog/js/clipboard-use.js" ></script>



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





  <script  src="https://cdn.staticfile.org/tocbot/4.11.1/tocbot.min.js" ></script>
  <script>
    $(document).ready(function () {
      var boardCtn = $('#board-ctn');
      var boardTop = boardCtn.offset().top;

      tocbot.init({
        tocSelector: '#tocbot',
        contentSelector: 'article.markdown-body',
        headingSelector: 'h1,h2,h3,h4,h5,h6',
        linkClass: 'tocbot-link',
        activeLinkClass: 'tocbot-active-link',
        listClass: 'tocbot-list',
        isCollapsedClass: 'tocbot-is-collapsed',
        collapsibleClass: 'tocbot-is-collapsible',
        collapseDepth: 0,
        scrollSmooth: true,
        headingsOffset: -boardTop
      });
      if ($('.toc-list-item').length > 0) {
        $('#toc').css('visibility', 'visible');
      }
    });
  </script>



  <script  src="https://cdn.staticfile.org/typed.js/2.0.11/typed.min.js" ></script>
  <script>
    var typed = new Typed('#subtitle', {
      strings: [
        '  ',
        "css 高效代码片段&nbsp;",
      ],
      cursorChar: "|",
      typeSpeed: 70,
      loop: true,
    });
    typed.stop();
    $(document).ready(function () {
      $(".typed-cursor").addClass("h2");
      typed.start();
    });
  </script>



  <script  src="https://cdn.staticfile.org/anchor-js/4.2.2/anchor.min.js" ></script>
  <script>
    anchors.options = {
      placement: "right",
      visible: "hover",
      
    };
    var el = "h1,h2,h3,h4,h5,h6".split(",");
    var res = [];
    for (item of el) {
      res.push(".markdown-body > " + item)
    }
    anchors.add(res.join(", "))
  </script>



  <script  src="/blog/js/local-search.js" ></script>
  <script>
    var path = "/blog/local-search.xml";
    var inputArea = document.querySelector("#local-search-input");
    inputArea.onclick = function () {
      searchFunc(path, 'local-search-input', 'local-search-result');
      this.onclick = null
    }
  </script>



  <script  src="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.css" />

  <script>
    $('#post img:not(.no-zoom img, img[no-zoom]), img[zoom]').each(
      function () {
        var element = document.createElement('a');
        $(element).attr('data-fancybox', 'images');
        $(element).attr('href', $(this).attr('src'));
        $(this).wrap(element);
      }
    );
  </script>







  
  
    <script>
      !function (e, t, a) {
        function r() {
          for (var e = 0; e < s.length; e++) s[e].alpha <= 0 ? (t.body.removeChild(s[e].el), s.splice(e, 1)) : (s[e].y--, s[e].scale += .004, s[e].alpha -= .013, s[e].el.style.cssText = "left:" + s[e].x + "px;top:" + s[e].y + "px;opacity:" + s[e].alpha + ";transform:scale(" + s[e].scale + "," + s[e].scale + ") rotate(45deg);background:" + s[e].color + ";z-index:99999");
          requestAnimationFrame(r)
        }

        function n() {
          var t = "function" == typeof e.onclick && e.onclick;
          e.onclick = function (e) {
            t && t(), o(e)
          }
        }

        function o(e) {
          var a = t.createElement("div");
          a.className = "heart", s.push({
            el: a,
            x: e.clientX - 5,
            y: e.clientY - 5,
            scale: 1,
            alpha: 1,
            color: c()
          }), t.body.appendChild(a)
        }

        function i(e) {
          var a = t.createElement("style");
          a.type = "text/css";
          try {
            a.appendChild(t.createTextNode(e))
          } catch (t) {
            a.styleSheet.cssText = e
          }
          t.getElementsByTagName("head")[0].appendChild(a)
        }

        function c() {
          return "rgb(" + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + ")"
        }

        var s = [];
        e.requestAnimationFrame = e.requestAnimationFrame || e.webkitRequestAnimationFrame || e.mozRequestAnimationFrame || e.oRequestAnimationFrame || e.msRequestAnimationFrame || function (e) {
          setTimeout(e, 1e3 / 60)
        }, i(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: fixed;}.heart:after{top: -5px;}.heart:before{left: -5px;}"), n(), r()
      }(window, document);
    </script>
  













</body>
</html>
